clear*
set maxvar 11000

global date _2025_10_28
cd "/Users/atri0032/Dropbox/World Bank/Temperature, poverty, and inequality/Estimations/"

******************************************************************************************
********************************** Table S2: The effects of temperature on poverty
******************************************************************************************

// Subnational level
* FE model 
use "${date}/_data/spid_for_analysis_v2.dta", clear

drop sample

local controls ln_GDPppp Unempilo agri manuf popgr 
 
estimates clear
qui reghdfe poor215 temp rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	levelsof code if e(sample), local(count1)
	local Ncountry1 : word count `count1'
	estadd scalar N_country = `Ncountry1'
	levelsof geo_code2_new if e(sample), local(count2)
	local Ncountry2 : word count `count2'
	estadd scalar N_subregion = `Ncountry2'
	quietly summ poor215 if e(sample)
	estadd sca depmean = r(mean) 
	est store m1
qui reghdfe poor365 temp rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	levelsof code if e(sample), local(count1)
	local Ncountry1 : word count `count1'
	estadd scalar N_country = `Ncountry1'
	levelsof geo_code2_new if e(sample), local(count2)
	local Ncountry2 : word count `count2'
	estadd scalar N_subregion = `Ncountry2'
	quietly summ poor365 if e(sample)
	estadd sca depmean = r(mean) 	
	est store m2
qui reghdfe poor685 temp rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle
	levelsof code if e(sample), local(count1)
	local Ncountry1 : word count `count1'
	estadd scalar N_country = `Ncountry1'
	levelsof geo_code2_new if e(sample), local(count2)
	local Ncountry2 : word count `count2'
	estadd scalar N_subregion = `Ncountry2'	
	quietly summ poor685 if e(sample)
	estadd sca depmean = r(mean) 	
	est store m3

local opts ///
	cells(b(star fmt(3)) se(par fmt(3))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N N_country N_subregion depmean r2, fmt(0 0 0 3 3) ///
	label("Observations" "No of countries" "No of regions" "R-squared")) ///
	eqlabels(none) mtitle("$2.15/day" "$3.65/day" "$6.85/day") ///
	collabels(,none) varlabels(temp "Temperature" rainfall_ave "Rainfall" humid "Humidity") varwidth(25) ///
	title("Table S2 - Subnational - FE")
	
esttab m*, `opts' 
esttab m* using "${date}/_tables/_tab_s2_sub_FE.csv", replace `opts' 

	
* Long difference model
use "${date}/_data/spid_for_analysis_v2.dta", clear

drop sample

local controls ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d   

bysort 	geo_code2_new (year): egen year_min = min(year)
bysort 	geo_code2_new (year): egen year_max = max(year)

keep if year == year_min | year == year_max

bysort geo_code2_new (year): gen n = _n
bysort geo_code2_new (year): gen N = _N
	keep if N==2
	
encode geo_code2_new, gen(id_region)	
xtset id_region n
foreach v in gini theil temp poor215 poor365 poor685 rainfall_sum humid ln_GDPppp Unempilo agri manuf edupri eduter popgr tech {
	gen `v'_d = D.`v'
}
	
collapse (mean) poor215_d poor365_d poor685_d gini_d theil_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d edupri_d eduter_d popgr_d tech_d, by(code geo_code2_new year)
	
estimates clear
qui reg poor215_d temp_d rainfall_sum_d humid_d `controls', cluster(geo_code2_new) 
	levelsof code if e(sample), local(count1)
	local Ncountry1 : word count `count1'
	estadd scalar N_country = `Ncountry1'
	levelsof geo_code2_new if e(sample), local(count2)
	local Ncountry2 : word count `count2'
	estadd scalar N_subregion = `Ncountry2'	
	est store m1
qui reg poor365_d temp_d rainfall_sum_d humid_d `controls', cluster(geo_code2_new) 
	levelsof code if e(sample), local(count1)
	local Ncountry1 : word count `count1'
	estadd scalar N_country = `Ncountry1'
	levelsof geo_code2_new if e(sample), local(count2)
	local Ncountry2 : word count `count2'
	estadd scalar N_subregion = `Ncountry2'
	est store m2
qui reg poor685_d temp_d rainfall_sum_d humid_d `controls', cluster(geo_code2_new)  	
	levelsof code if e(sample), local(count1)
	local Ncountry1 : word count `count1'
	estadd scalar N_country = `Ncountry1'
	levelsof geo_code2_new if e(sample), local(count2)
	local Ncountry2 : word count `count2'
	estadd scalar N_subregion = `Ncountry2'	
	est store m3

local opts ///
	cells(b(star fmt(3)) se(par fmt(3))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N N_country N_subregion r2, fmt(0 0 0 3) ///
	label("Observations" "No of countries" "No of regions" "R-squared")) ///	
	eqlabels(none) mtitle("$2.15/day" "$3.65/day" "$6.85/day") ///
	collabels(,none) varlabels(temp "Temperature" rainfall_ave "Rainfall" humid "Humidity") varwidth(25) ///
	title("Table S2 - Subnational - LD")
	
esttab m*, `opts' 
esttab m* using "${date}/_tables/_tab_s2_sub_LD.csv", replace `opts' 

	
//==========================//	

// Country level
* FE model 
use "${date}/_data/spid_for_analysis_v2.dta", clear

drop sample
local controls ln_GDPppp Unempilo agri manuf popgr 

collapse (mean) poor215 poor365 poor685 gini theil temp rainfall_sum humid ln_GDPppp Unempilo agri manuf edupri eduter popgr tech, by(code year)

estimates clear
qui reghdfe poor215 temp rainfall_sum humid ln_GDPppp Unempilo agri manuf popgr , absorb(code year) cluster(code) keepsingle
	quietly summ poor215 if e(sample)
	estadd sca depmean = r(mean) 	
	est store m1
qui reghdfe poor365 temp rainfall_sum humid ln_GDPppp Unempilo agri manuf popgr , absorb(code year) cluster(code) keepsingle	
	quietly summ poor365 if e(sample)
	estadd sca depmean = r(mean) 
	est store m2
qui reghdfe poor685 temp rainfall_sum humid ln_GDPppp Unempilo agri manuf popgr , absorb(code year) cluster(code) keepsingle	
	quietly summ poor685 if e(sample)
	estadd sca depmean = r(mean) 
	est store m3

local opts ///
	cells(b(star fmt(3)) se(par fmt(3))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N depmean r2, fmt(0 3 3) ///
	label("Observations" "R-squared")) ///	
	eqlabels(none) mtitle("$2.15/day" "$3.65/day" "$6.85/day") ///
	collabels(,none) varlabels(temp "Temperature" rainfall_ave "Rainfall" humid "Humidity") varwidth(25) ///
	title("Table S2 - National - FE")
	
esttab m*, `opts' 
esttab m* using "${date}/_tables/_tab_s2_nat_FE.csv", replace `opts' 

* Long difference model
use "${date}/_data/spid_for_analysis_v2.dta", clear

local controls ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d   

bysort 	geo_code2_new (year): egen year_min = min(year)
bysort 	geo_code2_new (year): egen year_max = max(year)

keep if year == year_min | year == year_max

bysort geo_code2_new (year): gen n = _n
bysort geo_code2_new (year): gen N = _N
	keep if N==2
	
encode geo_code2_new, gen(id_region)	
xtset id_region n
foreach v in gini theil temp poor215 poor365 poor685 rainfall_sum humid ln_GDPppp Unempilo agri manuf edupri eduter popgr tech {
	gen `v'_d = D.`v'
}
	
collapse (mean) poor215_d poor365_d poor685_d gini_d theil_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d edupri_d eduter_d popgr_d tech_d, by(code year)
	
estimates clear
qui reg poor215_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d, cluster(code) 	
	est store m1
qui reg poor365_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d, cluster(code) 
	est store m2
qui reg poor685_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d, cluster(code)  	
	est store m3
	
local opts ///
	cells(b(star fmt(3)) se(par fmt(3))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2, fmt(0 3) ///
	label("Observations" "R-squared")) ///	
	eqlabels(none) mtitle("$2.15/day" "$3.65/day" "$6.85/day") ///
	collabels(,none) varlabels(temp "Temperature" rainfall_ave "Rainfall" humid "Humidity") varwidth(25) ///
	title("Table S2 - National - LD")
	
esttab m*, `opts' 
esttab m* using "${date}/_tables/_tab_s2_nat_LD.csv", replace `opts' 

	
//==========================//	
	
// T-test: FE vs LD
* Country-level
use "${date}/_data/spid_for_analysis_v2.dta", clear

drop sample
local controls ln_GDPppp Unempilo agri manuf popgr

collapse (mean) poor215 poor365 poor685 temp rainfall_sum humid ln_GDPppp Unempilo agri manuf popgr, by(code year)

encode code, gen(id_country)

gen sample = "FE"
	
tempfile fe
save `fe'
	
use "${date}/_data/spid_for_analysis_v2.dta", clear

local controls ln_GDPppp Unempilo agri manuf popgr 

bysort 	geo_code2_new (year): egen year_min = min(year)
bysort 	geo_code2_new (year): egen year_max = max(year)

keep if year == year_min | year == year_max

bysort geo_code2_new (year): gen n = _n
bysort geo_code2_new (year): gen N = _N
	keep if N==2
	
encode geo_code2_new, gen(id_region)	
xtset id_region n
foreach v in gini theil temp poor215 poor365 poor685 rainfall_sum humid ln_GDPppp Unempilo agri manuf popgr {
	gen `v'_d = D.`v'
}
	
collapse (mean) poor215_d poor365_d poor685_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d, by(code year)
	
gen sample = "LD"
	
append using `fe' 
	
estimates clear
qui reg poor215 temp rainfall_sum humid i.id_country i.year ln_GDPppp Unempilo agri manuf popgr	if sample =="FE"
	est store poor215_fe
qui reg poor365 temp rainfall_sum humid i.id_country i.year ln_GDPppp Unempilo agri manuf popgr if sample =="FE"
	est store poor365_fe
qui reg poor685 temp rainfall_sum humid i.id_country i.year ln_GDPppp Unempilo agri manuf popgr if sample =="FE"
	est store poor685_fe

	
qui reg poor215_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d if sample =="LD"
	est store poor215_ld
qui reg poor365_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d if sample =="LD"
	est store poor365_ld
qui reg poor685_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d if sample =="LD"
	est store poor685_ld

qui suest poor215_fe poor215_ld	
test [poor215_fe_mean]temp - [poor215_ld_mean]temp_d = 0
qui suest poor365_fe poor365_ld	
test [poor365_fe_mean]temp - [poor365_ld_mean]temp_d = 0
qui suest poor685_fe poor685_ld	
test [poor685_fe_mean]temp - [poor685_ld_mean]temp_d = 0

* Subnational-level
use "${date}/_data/spid_for_analysis_v2.dta", clear

drop sample
local controls ln_GDPppp Unempilo agri manuf popgr

encode geo_code2_new, gen(id_region)

estimates clear
qui reg poor215 temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr
	est store poor215_fe
qui reg poor365 temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr
	est store poor365_fe
qui reg poor685 temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr
	est store poor685_fe
	
bysort 	geo_code2_new (year): egen year_min = min(year)
bysort 	geo_code2_new (year): egen year_max = max(year)

keep if year == year_min | year == year_max

bysort geo_code2_new (year): gen n = _n
bysort geo_code2_new (year): gen N = _N
	keep if N==2
	
xtset id_region n
foreach v in gini theil temp poor215 poor365 poor685 rainfall_sum humid ln_GDPppp Unempilo agri manuf popgr {
	gen `v'_d = D.`v'
}
	
qui reg poor215_d temp_d rainfall_sum_d humid_d	ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d
	est store poor215_ld
qui reg poor365_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d
	est store poor365_ld
qui reg poor685_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d
	est store poor685_ld

qui suest poor215_fe poor215_ld	
test [poor215_fe_mean]temp - [poor215_ld_mean]temp_d = 0
qui suest poor365_fe poor365_ld	
test [poor365_fe_mean]temp - [poor365_ld_mean]temp_d = 0
qui suest poor685_fe poor685_ld	
test [poor685_fe_mean]temp - [poor685_ld_mean]temp_d = 0

// T-test: country vs subnational
* FE model 
use "${date}/_data/spid_for_analysis_v2.dta", clear

drop sample
local controls ln_GDPppp Unempilo agri manuf popgr 

encode geo_code2_new, gen(id_region)

gen sample = "sub"
	
tempfile sub
save `sub'
	
collapse (mean) poor215 poor365 poor685 temp rainfall_sum humid ln_GDPppp Unempilo agri manuf popgr, by(code year)
encode code, gen(id_country)

gen sample = "nat"
	
append using `sub' 

estimates clear
qui reg poor215 temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr if sample =="sub"
	est store poor215_sub
qui reg poor365 temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr if sample =="sub"
	est store poor365_sub
qui reg poor685 temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr if sample =="sub"
	est store poor685_sub
	
qui reg poor215 temp rainfall_sum humid i.id_country i.year ln_GDPppp Unempilo agri manuf popgr if sample =="nat"
	est store poor215_nat
qui reg poor365 temp rainfall_sum humid i.id_country i.year ln_GDPppp Unempilo agri manuf popgr if sample =="nat"
	est store poor365_nat
qui reg poor685 temp rainfall_sum humid i.id_country i.year ln_GDPppp Unempilo agri manuf popgr if sample =="nat"
	est store poor685_nat

qui suest poor215_sub poor215_nat	
test [poor215_sub_mean]temp - [poor215_nat_mean]temp = 0
qui suest poor365_sub poor365_nat	
test [poor365_sub_mean]temp - [poor365_nat_mean]temp = 0
qui suest poor685_sub poor685_nat	
test [poor685_sub_mean]temp - [poor685_nat_mean]temp = 0

* LD model 
use "${date}/_data/spid_for_analysis_v2.dta", clear

drop sample
local controls ln_GDPppp Unempilo agri manuf popgr

bysort 	geo_code2_new (year): egen year_min = min(year)
bysort 	geo_code2_new (year): egen year_max = max(year)

keep if year == year_min | year == year_max

bysort geo_code2_new (year): gen n = _n
bysort geo_code2_new (year): gen N = _N
	keep if N==2
	
encode geo_code2_new, gen(id_region)	
xtset id_region n
foreach v in gini theil temp poor215 poor365 poor685 rainfall_sum humid ln_GDPppp Unempilo agri manuf popgr {
	gen `v'_d = D.`v'
}
	
gen sample = "sub"	
tempfile sub
save `sub'

use "${date}/_data/spid_for_analysis_v2.dta", clear

drop sample
local controls ln_GDPppp Unempilo agri manuf popgr 

bysort 	geo_code2_new (year): egen year_min = min(year)
bysort 	geo_code2_new (year): egen year_max = max(year)

keep if year == year_min | year == year_max

bysort geo_code2_new (year): gen n = _n
bysort geo_code2_new (year): gen N = _N
	keep if N==2
	
encode geo_code2_new, gen(id_region)	
xtset id_region n
foreach v in gini theil temp poor215 poor365 poor685 rainfall_sum humid ln_GDPppp Unempilo agri manuf popgr {
	gen `v'_d = D.`v'
}
	
collapse (mean) poor215_d poor365_d poor685_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d, by(code year)
	
gen sample = "nat"
	
append using `sub' 
	
estimates clear
qui reg poor215_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d if sample =="sub" 	
	est store poor215_sub
qui reg poor365_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d if sample =="sub"
	est store poor365_sub
qui reg poor685_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d if sample =="sub" 	
	est store poor685_sub
		
qui reg poor215_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d if sample =="nat" 	
	est store poor215_nat
qui reg poor365_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d if sample =="nat"
	est store poor365_nat
qui reg poor685_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d if sample =="nat" 	
	est store poor685_nat

qui suest poor215_sub poor215_nat	
test [poor215_sub_mean]temp_d - [poor215_nat_mean]temp_d = 0
qui suest poor365_sub poor365_nat	
test [poor365_sub_mean]temp_d - [poor365_nat_mean]temp_d = 0
qui suest poor685_sub poor685_nat	
test [poor685_sub_mean]temp_d - [poor685_nat_mean]temp_d = 0
	